import { useCloud } from '@/modules/cloud/index'
async function getCollectState(itemId = '') {

    const db = useCloud().database();
    const col = db.collection('collect');

    const { data } = await col.get()

    const target = data.find(item => {
        return item.itemId === itemId
    })

    console.log('getCollectState', target, data);
    return target
}
export default {
    async collectTarget({ data }) {
        const db = this.database();
        const postCol = db.collection('collect');

        const isCollect = await getCollectState(data.itemId)

        if (isCollect) {
            return {
                message: "你已经收藏过了"
            }
        }

        const req = {
            ...data,
            collectTimeStamp: new Date().getTime()
        }

        console.log('collcetVideo', req);


        const res = await postCol.add(req)


        return res
    },

    getCollectState
}